#include "WaterFlow.h"

WaterFlow::WaterFlow()
{
}

WaterFlow::~WaterFlow()
{

}

void WaterFlow::initGameObjectWith(GamePlayScreen *_gameScreen)
{
    PhysicObject::initGameObjectWith(_gameScreen);

    this->createSprite();
    this->createPhysicBody();
}

void WaterFlow::createSprite()
{
    objType = WATER;
    sprite = new CCSprite();
    sprite->initWithSpriteFrameName("water.png");
    sprite->setTag(WATER);
    sprite->setScaleX(handler->worldSize.width / sprite->getContentSize().width);
    sprite->setPosition(ccp(handler->worldSize.width / 2.f, sprite->getContentSize().height/2.f));
}

void WaterFlow::createPhysicBody()
{
    b2BodyDef bodyDef;
    bodyDef.type = b2_staticBody;

    bodyDef.userData = this;
    if (sprite) {
        bodyDef.position.Set(0, 0);
    }
    physicBody = handler->world->CreateBody(&bodyDef);

    b2FixtureDef fixtDef;
    b2PolygonShape polyShape;
    b2Vec2 center = b2Vec2(handler->worldSize.width / (PTM_RATIO*2.f), handler->deathLine / (2.f*PTM_RATIO));
    polyShape.SetAsBox(center.x, center.y, center, 0);
    fixtDef.shape = &polyShape;
    fixtDef.friction = 0.1f;
    fixtDef.restitution = 0.1f;
    fixtDef.density = 0.5f;
    fixtDef.isSensor = true;
    physicBody->CreateFixture(&fixtDef);
}
